package com.hotel.core.utils;

import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

public final class DataConversionUtil {
    private DataConversionUtil() {
    }

    public final static <T, E> T converteData(Class<T> entityClass, E source, String[] ignoreProperties) {
        T obj = (T) BeanUtils.instantiate(entityClass);
        BeanUtils.copyProperties(source, obj, ignoreProperties);
        return obj;
    }

    public final static <T, E> T converteData(Class<T> entityClass, E source) {
        T obj = (T) BeanUtils.instantiate(entityClass);
        BeanUtils.copyProperties(source, obj);
        return obj;
    }

    public final static <T, E> List<T> converteData(Class<T> entityClass, List<E> source) {
        List<T> target = new ArrayList<T>();
        for (E tmp : source) {
            target.add(converteData(entityClass, tmp));
        }
        return target;
    }

    public final static <T, E> List<T> converteData(Class<T> entityClass, List<E> source, String[] ignoreProperties) {
        List<T> target = new ArrayList<T>();
        for (E tmp : source) {
            target.add(converteData(entityClass, tmp, ignoreProperties));
        }
        return target;
    }

}
